package com.exercises;

import com.alibaba.fastjson.JSONObject;

import java.util.Stack;

class Exercise1109 {
    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 10};
        int[] b = new int[]{2, 3, 20};
        int[] c = new int[]{1, 5, 25};
        int[][] d = new int[][]{a, b, c};
        System.out.println(JSONObject.toJSONString(corpFlightBookings(d, 5)));
    }


    public static int[] corpFlightBookings(int[][] bookings, int n) {
        int[] result = new int[n];
        for (int[] booking : bookings) {
            int first = booking[0] - 1;
            int last = booking[1];
            int seats = booking[2];
            result[first] += seats;
            if (last <= n - 1) result[last] -= seats;
        }
        int pre = 0;
        for (int i = 0; i < n; i++) {
            result[i] = result[i] + pre;
            pre = result[i];
        }
        return result;
    }
}
